package org.vectrics.recruiter.job;

import java.io.Serializable;
import java.util.Comparator;


public class JobDateComparator implements  Comparator, Serializable {

	private static final long serialVersionUID = 455511197502465840L;
	public static int ASCENDING = 0;
    public static int DESCENDING = 0;
    private int mode = DESCENDING;

    public int compare(Object obj1, Object obj2) {
        int result = 0;
        JobSearchRating job2 = null;
        JobSearchRating job1 = null;
        if (mode == DESCENDING) {
            job2 = (JobSearchRating)obj1;
            job1 = (JobSearchRating)obj2;
        }
        else {
            job1 = (JobSearchRating)obj1;
            job2 = (JobSearchRating)obj2;
        }
        result = job1.getDatePosted().compareTo(job2.getDatePosted());
        
        if (result == 0) {
            if (job1.getRating() < job2.getRating()) {
                result = -1;
            }
            else if (job1.getRating() > job2.getRating()) {
                result = 1;
            }
            else if (job1.getJobId().equals(job2.getJobId()) == false) {
                result = 1;
            }
        }
        
        return(result);
    }
    
    public boolean equals(Object obj1) {
        return(obj1 == this);
    }
}
